package com.mazaiting.classfile.constant.info;

import com.mazaiting.classfile.ClassReader;
import com.mazaiting.classfile.constant.ConstantPool;
import com.mazaiting.classfile.constant.entity.NameAndType;

/**
 * 接口方法符号引用
 *
 * @author mazaiting
 * @since 2021/8/11
 */
public class ConstantInterfaceMethodRefInfo extends ConstantInfo {
    /**
     * 类索引 无符号 u2
     * CONSTANT_Class_info
     */
    private int classIndex;
    /**
     * 类型索引 无符号 u2
     * CONSTANT_NameAndType_info
     */
    private int nameAndTypeIndex;

    public ConstantInterfaceMethodRefInfo(ConstantPool pool) {
        super(pool);
    }

    @Override
    public void readInfo(ClassReader reader) {
        this.classIndex = reader.readU2ToUnsignedShort();
        this.nameAndTypeIndex = reader.readU2ToUnsignedShort();
    }

    /**
     * 获取类名
     * @return 类名
     */
    public String className() {
        return this.pool.getClassName(this.classIndex);
    }

    /**
     * 获取名称和类型
     * @return 名称和类型
     */
    public NameAndType nameAndDescriptor() {
        return this.pool.getNameAndType(this.nameAndTypeIndex);
    }

    @Override
    public String toString() {
        return "ConstantInterfaceMethodRefInfo{" +
                "classIndex=" + classIndex +
                ", nameAndTypeIndex=" + nameAndTypeIndex +
                '}';
    }
}


















